package com.hr.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author DSL
 * @create 2024-10-16 15:08
 */
@Data//set和get
@NoArgsConstructor//无参构造
@AllArgsConstructor//全参构造
public class Result <R>{
    private int code;//状态码
    private String message;//提示信息
    private R data;//返回数据
    public  Result(R data){
        this(200, "success", data);
    }
    public   Result(R data,boolean success,String message){
        if (success){
            this.code=200;
            this.message="success";
        }else {
            this.code=500;
            this.message=message;
        }
        this.data=data;
    }
    public Result(int code,String message){
        this.code=code;
        this.message=message;
        this.data=null;
    }
    public static<R> Result<R> success(R data){
        return new Result<>(data);
    }//成功
    public  static <R> Result<R> fail(String message){
        return  new Result<>(500,message);
    }//默认失败
    public  static <R> Result<R>fail(int code,String message){
        return new Result<>(code,message);
    }//自定义失败
}
